'''
Created on May 10, 2012

@author: thomas_dao
'''

'''
Chat module supports group message in real time
It uses GAE Channel API
'''
import base
from base import BaseHandler
from web import urls
from web import util
from google.appengine.api import channel

class ChatHandler(BaseHandler):
    """
    Show all details belong to an event
    """
    @base.user_required
    def get(self):
        template = util.jinja_environment().get_template('chat-page.html')
        token = channel.create_channel(str(util.get_current_user_key().id()))
        template_values = {'token': token}
        self.response.out.write(template.render(template_values))
        
    @base.user_required
    def post(self):
        friend_list = self.request.params.get('friend').split(",")
        message = self.request.params.get('message')
        for friend in friend_list:
            channel.send_message(friend, message)

app = urls.app

def main():
    app.run()

if __name__ == '__main__':
    main()